package com.bosicen.crm.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import com.bosicen.crm.tools.AppUtil;


/*****
 * 拦截器
 * @author niyong
 *
 */
public class WebSessionInterceptor extends HandlerInterceptorAdapter {

	 @Override  
	       public boolean preHandle(HttpServletRequest req, HttpServletResponse resp, Object handler) {  
	      
		 try {
		 	   String path=req.getRequestURL().toString();
		 	   String[] str=path.split("/");
				String s=str[str.length-1];
	           Object session=req.getSession().getAttribute("userinfo");
	           if (!s.equals("index")&&session==null&&!s.equals("findimagecode")) {
					resp.sendRedirect(req.getContextPath()+"/index.jsp?msg="+AppUtil.URLEncoder2UTF8("登陆信息失效,请重新登陆!"));
	                return false;
	           }  
		    } catch (Exception e) {

				e.printStackTrace();
			}  
	           return true;  
	      }  
}
